package com.galeno.zoopeeper;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

/**
 * @author galeno
 * @Title:
 * @Description:
 * @date 2021/7/319:49
 */
public class NameNode {
   static ZooKeeper zk=null;

  public static void main(String[] args) {



  }

    public static void start() throws IOException {
        String path="galeno01:2181";
    zk =
        new ZooKeeper(
            path,
            2000,
            new Watcher() {
              @Override
              public void process(WatchedEvent event) {
                System.out.println("namenode上线");
              }
            });
    }
    static void reg() throws InterruptedException, KeeperException {
        List<String> children = zk.getChildren("/datanodes", new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                //Event.EventType type = event.getType();
                String path = event.getPath();
                try {
                    List<String> children1 = zk.getChildren(path, null);

                } catch (KeeperException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        });
        List<String> dns=new LinkedList<>();
    for (String child : children) {
      //
        byte[] data = zk.getData("/datanodes" + child, null, null);
        String hostname = new String(data);
        dns.add(hostname
        );
    }
    }
}
